<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>发布新投票</title>
    <link rel="stylesheet" type="text/css" th:href="@{/mystatic/bootstrap-3.4.1-dist/css/bootstrap.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/mystatic/bootstrap-3.4.1-dist/css/bootstrap-theme.css}" />
    <script type="text/javascript"  th:src="@{/mystatic/js/jquery-1.8.3.js}"></script>
</head>
<body>
<h2 align="center" >编辑投票</h2>
<div class="container-fluid" >
    <div class="row">
        <div class="col-md-2"></div>
        <div class="col-md-8">
            <form class="form-horizontal" th:action="@{/adminEditOption}"  method="post">
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">投票内容</label>
                    <div class="col-sm-10">
                        <input type="hidden" name="vs_id" th:value="${sub.vs_id}"  />
                        <input type="text" class="form-control" id="title" th:value="${sub.vs_title}"  name="vs_title" placeholder="输入投票内容...">
                    </div>
                </div>
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">投票类型</label>
                    <div class="radio">
                        <div class="col-sm-10">
                            <label>
                                <input type="radio" name="vs_type" th:checked="${#request.getAttribute('sub') != null and  #request.getAttribute('sub').vs_type eq 1}" id="blankRadio1" value="1" aria-label="..."> 单选
                            </label>
                            <label>
                                <input type="radio" name="vs_type" th:checked="${sub.vs_type eq 2}" id="blankRadio2" value="2" aria-label="..."> 多选
                            </label>
                        </div>
                    </div>
                </div>
                <!--<c:forEach var="v" items="${requestScope.op}" >-->
                    <div th:each="v:${op}" class="form-group" id="voteoptions">
                        <label  class="col-sm-2 control-label">投票选项 </label>
                        <div class="col-sm-8">
                            <input type="hidden"  name="ids" th:value="${v.vo_id}" />
                            <input type="text" class="form-control" id="title" th:value="${v.vo_option}"   name="ops" placeholder="输入选项内容...">
                        </div>
                        <div class="col-sm-2"  ><a href="javascript:void(0)" th:onclick="myOptionDel('[[${v.vo_id}]]', '[[${sub.vs_id}]]' )" > 删除 </a>  </div>
                    </div>
                <!--</c:forEach>-->
                <!-- <c:if test="${requestScope.op == null || fn:length(requestScope.op) == 0}">-->
                    <div th:if="${op eq null}" class="form-group" id="voteoptions">
                        <label  class="col-sm-2 control-label">投票选项 </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="title" name="ops" placeholder="输入选项内容...">
                        </div>
                        <label for="title" class="col-sm-2 control-label"> </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="title" name="ops" placeholder="输入选项内容...">
                        </div>
                    </div>
                <!--</c:if>-->

                <div class="form-group" id="addOptionDiv">
                    <label  class="col-sm-2 control-label">
                        &nbsp;
                    </label>
                    <label  class="col-sm-2 control-label">
                        <input type="submit" name="sub" class="btn btn-success btn-sm" value="确认修改" />
                    </label>
                    <label  class="col-sm-2 control-label">
                        <input type="button" name="btn" id="addOption" class="btn btn-info btn-sm" value="增加选项" />
                    </label>
                </div>
            </form>
        </div>
        <div class="col-md-2"></div>
    </div>
    <script th:if="${session.deloperr != null}" type="text/javascript">
        alert("该选项已经被投过票了,不能被删除");
        [(${#session.removeAttribute('deloperr')})]
    </script>
    <script th:if="${session.delopok != null}" type="text/javascript">
        alert("删除选项成功");
        [(${#session.removeAttribute('delopok')})]
    </script>
</body>
<script type="text/javascript">
    $(function(){
        //alert("abc");
        $("#addOption").click(function(){
            var $p=$('<div class="form-group" id="voteoptions" ></div>');
            var $text=$('<label  class="col-sm-2 control-label" />   </label> <div class="col-sm-8"> <input type="text" class="form-control" name="ops"  placeholder="输入选项内容..." /> </div>');
            var $del=$('<div class="col-sm-2"> <a href="javascript:void(0)" >删除</a></div> ');
            $del.click(function(){
                $(this).parent().remove();
            });
            $p.append($text).append($del);
            //$("#voteoptions").append($p);
            $("#addOptionDiv").before($p);
        });
    });
    function myOptionDel(oid,vsid){
        var boo = window.confirm("确定删除吗?删除后数据无法恢复!!!");
        if(boo == true){
            window.location.href="deleteOptionByid?opid="+oid+"&vsid="+vsid;
        }
    }
</script>
</body>
</html>
